<template>
	<view style=" background-image: linear-gradient(#f4f4f4 , #ffffff);">
		<view class="px-3 main-bg-color position-relative" style="height: 300upx;">
			<view class="row main-text-color-bai a-center j-sb" style="height: 130upx;padding-top:30upx;">
				<view class="row a-center" style="height: 126upx;">
					<image :src="headimgurl" style="width: 126upx;height: 126upx;border-radius: 50%;overflow: hidden;"></image>
					<view class="pl-2">
						<view class="">
							{{nickname}}
						</view>
						<view class="">
							邀请码：{{userinfos.invite_code}}
						</view>
					</view>
				</view>
				<view @tap="qrcode()" class="row a-center px-2">
					
					<image src="../../static/my_qrcode.png" style="width: 35upx;height: 35upx;"></image>
				</view>
			</view>
		</view>
		<view class="cash" style="background-color:#FFFFFF;width:700upx;height:270upx;position:fixed;top:280upx;margin-left:25upx;border-radius:10upx;padding-bottom: 20rpx;">
			<view class="cash_box">
				<view class="cash_score">
					<view>{{myScores.score}}</view>
					<text>可提金额</text>
				</view>
				<view class="cash_score">
					<view>{{myScores.withdrawing_money}}</view>
					<text>在提金额</text>
				</view>
				<view class="cash_score">
					<view>{{myScores.withdrawed_money}}</view>
					<text>已提金额</text>
				</view>
			</view>
			<view style="width:600upx;height:1upx;border-top:1upx solid #f6f6f6;margin:auto;margin-top:180upx;"></view>
			<view class="cash_withdraw">
				<view class="cash_withdraw_l">
					<!-- <text>剩余</text>
					<text>{{myScores.score}}</text> -->
					<text style="font-size:32upx;color:#111111;font-family: Arial;">{{myScores.score}}</text>
					<text style="color:#999999;font-size:24upx;">积分</text>
				</view>
				<view class="cash_withdraw_r" @tap="withdraw()">
					<view class="cash_withdraw_button">去提现</view>
				</view>
			</view>
			<!-- <view style="width:600upx;height:1upx;border-top:1upx solid #e6e6e6;margin:auto;margin-top:100upx;"></view> -->
		</view>
		<view>
			<view class="row" style="width:700upx;margin:25upx;margin-top:200upx;">
				<block v-for="(item,index) in distributionTab" :key="index">
					<view class="d-flex flex-column a-center right_bottom_border"
					@tap="event(item)" style="width:230upx;padding-top:50upx;padding-bottom:50upx;border:1upx solid #f6f6f6;">
						<image :src="item.src" 
						style="width: 65upx;height: 65upx;"
						mode="aspectFit" class="mb-2"></image>
						<text class=" font-sm">{{item.text}}</text>
					</view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				userinfos:'',
				agent_level:'',
				myScores:'',
				nickname:uni.getStorageSync('keyNickname'),
				headimgurl:uni.getStorageSync('keyHeadimgurl'),
				distributionTab:[{
					path:'/pages/distribution/score',
					src:'../../static/distributiontab1.png',
					text:'分销积分'
				},
				{
					path:'/pages/distribution/order',
					src:'../../static/distributiontab2.png',
					text:'分销订单'
				},
				{
					path:'/pages/distribution/withdrawdetail',
					src:'../../static/distributiontab3.png',
					text:'提现明细'
				},
				{
					path:'/pages/distribution/team',
					src:'../../static/distributiontab4.png',
					text:'我的团队'
				},
				{
					path:'/pages/distribution/qrcode',
					src:'../../static/distributiontab5.png',
					text:'推广二维码'
				}],
			}
		},
		onLoad:function(){
			uni.request({
				url: request.common.baseUrl+'/api/users/userinfos',
				data: {
					token:uni.getStorageSync('keyToken')
				},
				header: {
					'Content-Type':'application/json;charset=UTF-8',
					'Content-Type':'application/x-www-form-urlencoded'
				},
				success: (res) => {
					if(res.data.code==200){
						this.userinfos=res.data.data
					}
				}
			});
			uni.request({
				url: request.common.baseUrl+'/api/distributor/myScore',
				data: {
					token:uni.getStorageSync('keyToken')
				},
				header: {
					'Content-Type':'application/json;charset=UTF-8',
					'Content-Type':'application/x-www-form-urlencoded'
				},
				success: (res) => {
					console.log(res)
					if(res.data.code==200){
						this.myScores=res.data.data
					}
				}
			});
		},
		methods: {
			event(item){
				uni.navigateTo({
					url:item.path+"?invite_code="+this.userinfos.invite_code
				})
			},
			qrcode(){
				uni.navigateTo({
					url:"/pages/distribution/qrcode?invite_code="+this.userinfos.invite_code
				})
			},
			withdraw(){
				uni.navigateTo({
					url:"/pages/distribution/withdraw?score="+this.myScores.score
				})
			}
		},
		onShow() {
			if(uni.getStorageSync('keyToken')){
				if(uni.getStorageSync('keyNickname')){
					this.nickname=uni.getStorageSync('keyNickname');
					this.headimgurl=uni.getStorageSync('keyHeadimgurl');
					if(uni.getStorageSync('keyAgent_level')==1){
						this.agent_level='门店'
					}else if(uni.getStorageSync('keyAgent_level')==2){
						this.agent_level='代理'
					}else if(uni.getStorageSync('keyAgent_level')==3){
						this.agent_level='区域'
					}else if(uni.getStorageSync('keyAgent_level')==4){
						this.agent_level='市代'
					}else{
						if(uni.getStorageSync('keyDistributor_state')==1){
							this.agent_level='会员'
						}else{
							this.agent_level='普通'
						}
					}
				}else{
					uni.request({
						url: request.common.baseUrl+'/api/users/userinfos',
						data: {
							token:uni.getStorageSync('keyToken')
						},
						header: {
							'Content-Type':'application/json;charset=UTF-8',
							'Content-Type':'application/x-www-form-urlencoded'
						},
						success: (res) => {
							if(res.data.code==200){
								this.nickname=res.data.data.nickname
								this.headimgurl=res.data.data.headimgurl
								if(res.data.data.agent_level==1){
									this.agent_level='门店'
								}else if(res.data.data.agent_level==2){
									this.agent_level='代理'
								}else if(res.data.data.agent_level==3){
									this.agent_level='区域'
								}else if(res.data.data.agent_level==4){
									this.agent_level='市代'
								}else{
									if(res.data.data.distributor_state==1){
										this.agent_level='会员'
									}else{
										this.agent_level='普通'
									}
								}
							}
						}
					});
				}
			}
		}
	}
</script>

<style>
.right_bottom_border:nth-child(1){
	border-right-style:unset !important;
	border-bottom-style:unset !important;
}
.right_bottom_border:nth-child(2){
	border-right-style:unset !important;
	border-bottom-style:unset !important;
}
.right_bottom_border:nth-child(4){
	border-right-style:unset !important;
}
.cash_score{
	width:233upx;
	float:left;
	text-align:center;
	padding-top:25upx;
	padding-bottom:25upx;
}
.cash_score view{
	font-size:32upx;
	color:#111111;
	font-family: Arial;
}
.cash_score text{
	color:#999999;
	font-size:24upx;
}
.cash_withdraw{
	margin:12upx 50upx;
	margin-top:24upx;
}
.cash_withdraw_l{
	float:left;
}
.cash_withdraw_l text:nth-child(1){
	font-size:24upx;
	color:#666666;
}
.cash_withdraw_l text:nth-child(2){
	font-size:32upx;
	color:#111111;
	margin-left:10upx;
}
.cash_withdraw_r{
	float:right;
}
.cash_withdraw_button{
	background-color:#2ed50b;
	color:#FFFFFF;
	font-size:24upx;
	border-radius:30upx;
	padding:10upx 30upx;
}
</style>
